<template>
    <div>
        <!--角色天界页面-->
        <van-field  label='角色名' placeholder="请输入" v-model="name"></van-field>
        <van-button @click="add">添加角色</van-button>
        <br>
        <br>
        <br>
        角色表
        <ul>
            <li v-model="roles_id" v-for="i in roleslist">{{i.name}}
            <router-link :to="{path:'/roles_resources',query:{id:i.id}}">权限设置</router-link>
            </li>
        </ul>

    </div>
</template>

<script>
    export default {
        data() {
            return {
                name:'',
                roleslist:[],
                roles_id:''
            }
        },
        methods: {
             //获取角色
            getroles(){
                this.$axios.get('/user/rolesadd/').then(res=>{
                    this.roleslist = res.data.list
                    
                })
            },
            add(){
                if(this.name == ''){
                    this.$toast.fail('请填写角色名')
                    return false
                }
                this.$axios.post('/user/rolesadd/',{name:this.name}).then(res=>{
                    if(res.data.code == 200){
                        this.$toast.success(res.data.msg)
                    }else{
                        this.$toast.fail(res.data.msg)
                    }
                })
            }
        },
        mounted() {
            this.getroles()
        },
    }
</script>

<style scoped>

</style>